package com.syc.mybatis.dao;

import org.apache.ibatis.session.SqlSession;

import com.syc.mybatis.domain.Person;
import com.syc.mybatis.utils.MyBatisUtil;

public class PersonDao {

	public Person findById(int id) {
		try {
			SqlSession session = MyBatisUtil.getSqlSession();

			Person person = session.selectOne(Person.class.getName() + ".findById", id);

			session.commit();

			return person;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		} finally {
			MyBatisUtil.closeSqlSession();
		}
	}

	public Person findByName(String name) {
		try {
			SqlSession session = MyBatisUtil.getSqlSession();

			Person person = session.selectOne(Person.class.getName() + ".findByName", name);

			session.commit();

			return person;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		} finally {
			MyBatisUtil.closeSqlSession();
		}
	}
	
	
}
